package icegps.com.pingdj.activity.settingactivity;

import android.widget.TextView;

import butterknife.BindView;
import icegps.com.pingdj.R;
import icegps.com.pingdj.activity.BaseActivity;
import icegps.com.pingdj.bean.DeviceStatus;
import icegps.com.pingdj.data.ble.WriteHelper;
import icegps.com.pingdj.utils.DateFormat;

/**
 * Created by 111 on 2018/3/20.
 */

public class AboutActivity extends BaseActivity {
    @BindView(R.id.tv_device_mode)
    TextView tvDeviceMode;
    @BindView(R.id.tv_device_imei)
    TextView tvDeviceImei;
    @BindView(R.id.tv_software_version)
    TextView tvSoftwareVersion;
    @BindView(R.id.tv_card_model)
    TextView tvCardModel;
    @BindView(R.id.tv_number_model)
    TextView tvNumberModel;
    @BindView(R.id.tv_activation_info)
    TextView tvActivationInfo;

    @Override
    protected String setTitle() {
        return getString(R.string.about);
    }

    @Override
    protected void init() {
        WriteHelper.write(WriteHelper.GET_VER);
        setDeviceInfo();
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_about;
    }

    @Override
    public void onAnalysisAscDeviceStatus(DeviceStatus deviceStatus) {
        super.onAnalysisAscDeviceStatus(deviceStatus);
        setDeviceInfo();
    }

    private void setDeviceInfo() {
        if (deviceStatus.getActivateInfo() != null)
            tvActivationInfo.setText(deviceStatus.getActivateInfo());

        if (deviceStatus.getCardMode() != null)
            tvCardModel.setText(deviceStatus.getCardMode());

        if (deviceStatus.getDeviceImei() != null)
            tvDeviceImei.setText(deviceStatus.getDeviceImei());

        if (deviceStatus.getNumberMode() != null)
            tvNumberModel.setText(deviceStatus.getNumberMode());

        if (deviceStatus.getSoftwareVersion() != null)
            tvSoftwareVersion.setText(deviceStatus.getSoftwareVersion());

        if (deviceStatus.getDeviceMode() != null)
            tvDeviceMode.setText(deviceStatus.getDeviceMode());

        if (deviceStatus.getActivateInfo() != null)
            if ("OPEN".equals(deviceStatus.getActivateInfo())) {
                tvActivationInfo.setText(R.string.permanent_activation);
            } else {
                tvActivationInfo.setText(DateFormat.time2Date(Long.parseLong(deviceStatus.getActivateInfo()) * 1000) + getString(R.string.expire));
            }
    }
}
